package com.grudesign.stutrip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.grudesign.stutrip.common.ReturnInfo;
import com.grudesign.stutrip.entity.Po.TriplinePo;
import com.grudesign.stutrip.mapper.TriplineMapper;
import com.grudesign.stutrip.service.TriplineService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 研学线路表 服务实现类
 * </p>
 *
 * @author wx
 * @since 2022-05-09
 */
@Service
public class TriplineServiceImpl extends ServiceImpl<TriplineMapper, TriplinePo> implements TriplineService {


    @Override
    public Object getTrips(String cur, String li) {
        Page<TriplinePo> page = new Page<>(Long.parseLong(cur),Long.parseLong(li));
        Page<TriplinePo> tripPage = baseMapper.selectPage(page, Wrappers.emptyWrapper());
        return new ReturnInfo("200","ok").data("tripLinesInfo",tripPage);
    }

    @Override
    public Object getQuryTrips(String cur, String li, TriplinePo po) {
        if(null==po){
            return new ReturnInfo("200","ok").data("tripLinesInfo",getTrips(cur,li));
        }
        String lineName = po.getLineName();
        Page<TriplinePo> poPage = new Page<>(Long.parseLong(cur),Long.parseLong(li));
        QueryWrapper <TriplinePo> triplWrap = Wrappers.query();
        if(StringUtils.hasText(lineName)){
            triplWrap.like("line_name",lineName);
        }
        Page<TriplinePo> triplinePoPage = baseMapper.selectPage(poPage, triplWrap);
        return new ReturnInfo("200","ok").data("tripLinesInfo",triplinePoPage);
    }
}
